/* 16/9 - Raghu - The changes are not yet complete. this is only copied and modified class. Skeleton only
 * 
 * 
 * 
 */
using System;
using System.Collections.Generic;
using System.Text;

namespace TidhiGanitam.DataModel
{
    public  class KujuduRoutineItem
    {
        
        int m_iIndex;
        DateTime m_Date;
        Rasi m_NirayanaKujaKendram;
        Rasi m_NirayanaMadyamaKujudu;
        MandaRaviItem m_MandaKujuduItem;
        Rasi m_NakshatraPramanam;
        int m_iBhagam;
        int m_iSign = 1;
        public int Sign
        {
            get { return m_iSign; }
        }
        public int Bhagam
        {
            get { return m_iBhagam; }
        }
        public DateTime Date
        {
            get { return m_Date; }
        }
        public Rasi KujaKendram
        {
            get { return m_NirayanaKujaKendram; }
        }
        public Rasi MadyamaKujudu
        {
            get { return m_NirayanaMadyamaKujudu; }
        }
        public Rasi ChandraPhalam
        {
            get { return m_NakshatraPramanam; }
        }
        /*
        public Rasi RaviMandaPhalam
        {
            get { return m_MandaKujuduItem.MandaPadakam; }
        }
        public Rasi Gati
        {
            get { return m_MandaKujuduItem.Gati; }
        }
        public Degree Karnam
        {
            get { return m_MandaKujuduItem.Karnam; }
        }
        */
        public KujuduRoutineItem(int Bhagam, Rasi NirayanaKujaKendram, Rasi NirayanaMadyamaKujudu, DateTime Date)
        {
            m_iBhagam = Bhagam;
            m_NirayanaKujaKendram = new Rasi(NirayanaKujaKendram);
            m_NirayanaMadyamaKujudu = new Rasi(NirayanaMadyamaKujudu);
            m_Date = Date;
            m_iIndex = (int)(NirayanaKujaKendram.Rasulu * 30 + NirayanaKujaKendram.Bhagalu);
            //m_MandaRaviItem = (MandaRaviItem)Constants.MandaRaviPadakalu[m_iIndex];
            //m_MandaKujuduItem = Constants.GetMandaRaviItem(m_iIndex);
            m_NakshatraPramanam = new Rasi();
        }
         
        public void Calculate()
        {
            /* 
            Rasi MandaPhalamDiff;
            Rasi GatiDiff;
            Degree KarnamDiff;
            Rasi MadyamaRaviKendramAdvancement = new Rasi(0, 0, m_NirayanaKujaKendram.Liptalu, m_NirayanaKujaKendram.Viliptalu);
            if (m_iIndex < 360)
            {
                //Find out the Advancements for Manda Ravi Phalam, Gati and Karnam
                //MandaRaviItem NextMandaRaviItem = (MandaRaviItem)Constants.MandaRaviPadakalu[m_iIndex + 1];
                MandaRaviItem NextMandaRaviItem = (MandaRaviItem)Constants.GetMandaRaviItem (m_iIndex + 1);
                MandaPhalamDiff = Rasi.Difference(NextMandaRaviItem.MandaPadakam,m_MandaKujuduItem.MandaPadakam);
                GatiDiff = Rasi.Difference(NextMandaRaviItem.Gati, m_MandaKujuduItem.Gati);
                KarnamDiff = Degree.Difference(NextMandaRaviItem.Karnam, m_MandaKujuduItem.Karnam);
                if (MadyamaRaviKendramAdvancement.Liptalu > 0 || MadyamaRaviKendramAdvancement.Viliptalu > 0)
                {
                    MandaPhalamDiff = ((Rasi)(MandaPhalamDiff * MadyamaRaviKendramAdvancement)).Round();
                    GatiDiff = ((Rasi)(GatiDiff * MadyamaRaviKendramAdvancement)).Round();
                    KarnamDiff = KarnamDiff * new Degree(MadyamaRaviKendramAdvancement.Rasulu*30+ MadyamaRaviKendramAdvancement.Bhagalu,
                                MadyamaRaviKendramAdvancement.Liptalu, MadyamaRaviKendramAdvancement.Viliptalu);
                }
            }
            else
            {
                MandaPhalamDiff = new Rasi();
                GatiDiff = new Rasi();
                KarnamDiff = new Degree();
            }
            m_MandaKujuduItem.MandaPadakam += MandaPhalamDiff;
            m_MandaKujuduItem.Gati += GatiDiff;
            m_MandaKujuduItem.Karnam += KarnamDiff;
            //If kendram is between 0-0-0-0 and 5-29-59-59 Subtract MandaRaviPhalam Difference
            //If kendram is between 6-0-0-0 and 11-29-59-59 Add MandaRaviPhalam Difference
            if (m_NirayanaKujaKendram < new Rasi(5, 29, 59, 59))
            {
                //Calculate madhyama ravi
                m_NirayanaMadyamaKujudu -= m_MandaKujuduItem.MandaPadakam;
                m_iSign = -1;
            }
            else
            {
                //Calculate madhyama ravi
                m_NirayanaMadyamaKujudu += m_MandaKujuduItem.MandaPadakam;
                m_iSign = 1;
            }
            //Find the Nakshatra Pramanam
            m_NakshatraPramanam = ((Rasi)( m_MandaKujuduItem.MandaPadakam / 27)).Round();

            m_NirayanaMadyamaKujudu.Refresh();
            m_NirayanaKujaKendram.Refresh();
            */
        }


    }
}
